//
//  tex_rect_v1.hpp
//  OpenLearn
//
//  Created by korion chen on 2020/3/17.
//  Copyright © 2020 korion. All rights reserved.
//

#ifndef tex_rect_v1_hpp
#define tex_rect_v1_hpp

#include <stdint.h>
#include <GLFW/glfw3.h>

class TexRectV1 {
    
private:
    
    static const float vertices[32];
    
    static const uint32_t index[6];
    
    const char* vertex_shader_code = ""
        "#version 330 core\n"
        "layout (location = 0) in vec3 pos;\n"
        "layout (location = 1) in vec3 color;\n"
        "layout (location = 2) in vec2 texPos;\n"
        "out vec3 ourColor;\n"
        "out vec2 TexPos;\n"
        "void main()\n"
        "{\n"
        "    gl_Position = vec4(pos, 1.0);\n"
        "    ourColor = color;\n"
        "    TexPos = texPos;\n"
        "}\n";
    
    const char* fragment_shader_code = ""
        "#version 330 core\n"
        "in vec3 ourColor;\n"
        "in vec2 TexPos;\n"
        "out vec4 FragColor;\n"
        "uniform float tran;\n"
        "uniform sampler2D texture0;\n"
        "uniform sampler2D texture1;\n"
        "void main()\n"
        "{\n"
        "    FragColor = mix(texture(texture0, TexPos), texture(texture1, TexPos), tran);\n"
        "}\n";
    
    uint32_t VBO;
    
    uint32_t VAO;
    
    uint32_t EBO;
    
    uint32_t mProgram;
    
    uint32_t texture0;
    
    uint32_t texture1;

    bool hasInit = false;
    
    int createShader(int, const char*);
    int createProgram();
    int loadTexture(const char*, bool);
    
    
public:
    bool init();
    
    void drawSelf(GLFWwindow *window, float);
    
    void destroy();
};

#endif /* tex_rect_v1_hpp */
